<template>
	<div class="Box">
		<!-- 输入任意文本 -->
		<van-field v-model="dept" label-width="10em" type="text" autosize placeholder="请输入单位名称" label="单位名称：" />
		<!-- 选择日历 -->
		<van-cell title-style="text-align:left" title="请选择日期" icon="calendar-o" :value="calDate" @click="calShow = true" />
		<van-calendar v-model="calShow" @confirm="onConfirm" />
		<!-- 填报人 直接获取-->
		<van-field v-model="uploader" label-width="10em" type="text" autosize placeholder="请输入填报人" label="填报人姓名：" />
		<!-- 填报人电话 -->
		<van-field v-model="phone" label-width="10em" type="text" autosize placeholder="请输入填报人电话" label="填报人电话：" />
		<!-- 当日主要工作和数据 -->
		<div class="picTitle1">当日主要工作和数据：</div>
		<div class="jobContent">
			<van-field v-model="content" rows="1" autosize label="" label-width="10em" type="textarea" input-align="left" placeholder="请输入当日主要工作和数据" />
		</div>
		<van-divider :style="{ margin: '0px' }" />
		<!-- 工作亮点 -->
		<van-field v-model="workStar" rows="1" autosize label="当日工作亮点：" label-width="10em" type="textarea" placeholder="请输入工作亮点" />
		<!-- 其他需要协调的事项 -->
		<van-field v-model="other" rows="1" autosize label="其他需要协调的事项：" label-width="10em" type="textarea" placeholder="请输入其他需要协调的事项" />
		<div class="picTitle1">请选择附件：</div>
		<!-- 附件上传 -->
		<van-uploader v-model="fileList" upload-icon="peer-pay" preview-size="5em" multiple accept=".doc,.docx,image/*,.pdf,video/*,.txt,.xlsx,.xls" />

		<div class="bottomBtn" @click="tanchu">提交</div>
		<div style="margin-top: 0.6rem; height: 2rem"></div>
	</div>
</template>
<script>
import axios from 'axios'
import { Dialog, Toast } from 'vant'
import dd from 'gdt-jsapi'
export default {
	name: 'Report',
	data() {
		return {
			unitName: '',
			calShow: false,
			//数据
			dept: '',
			calDate: '',
			uploader: '',
			phone: '',
			content: '',
			workStar: '',
			workGroup: '工作组',
			other: '',
			fileList: [],
			employeeCode: null, //员工code
			organizationCode: null, //组织code
			govEmpPosJob: '', //员工职位
			organizationName: '', //员工组织
			empPosUnitCode: ''
		}
	},
	computed: {
		// list(){
		//     return JSON.parse(localStorage.item)
		// }
	},
	mounted() {
		document.title = '工作日志'
		let that = this
		async function getUser() {
			//获取accessToken
			let accessTokenData = await axios.get(`${window.baseURL}/api/hzd/gettoken.json`)
			let accessToken = accessTokenData.data.content.data.accessToken
			//获取authCode
			let authCode = dd.getAuthCode({ corpId: '' })
			//获取用户信息
			let userContentData = axios.post(`${window.baseURL}/api/hzd/getUserinfo`, { access_token: accessToken, auth_code: authCode })
			let userContent = JSON.parse(userContentData.data.content)
			console.log(userContent)
			let employeeCode = userContent.data.employeeCode
			that.employeeCode = userContent.data.employeeCode
			that.eventPeople = userContent.data.lastName
			//获取用户职位
			let govEmpPosJob = axios.get(`${window.baseURL}/api/hzd/getUserJob?employeeCode=${employeeCode}`)
			let userContent1 = JSON.parse(govEmpPosJob.data.content)
			console.log(userContent1)
			let organizationCode = userContent1.data.organizationCode
			that.govEmpPosJob = userContent1.data.govEmpPosJob
			that.organizationCode = userContent1.data.organizationCode
			//获取用户组织
			let userContent2 = axios.get(`${window.baseURL}/api/hzd/getOrganization?organizationCode=${organizationCode}`)
			userContent2 = JSON.parse(res4.data.content)
			that.organizationName = userContent2.data.organizationName
			console.log(userContent2)
		}
		getUser()
	},
	methods: {
		formatDate(date) {
			console.log(date)
			return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
		},
		onConfirm(date) {
			this.calShow = false
			this.calDate = this.formatDate(date)
		},
		tanchu() {
			Dialog.confirm({
				title: '确认提交？',
				message: '提交后无法修改，确认提交请点击“确认”按钮',
				confirmButtonColor: '#2074D4'
			})
				.then(() => {
					// on confirm
					this.upload()
				})
				.catch(() => {
					// on cancel
				})
		},
		// myM(.){

		// },
		// myP(){
		//     return new Promise((resolve,reject)=>{
		//         myM()
		//     })
		// },
		upload() {
			this.$store.commit('showLoading')
			let eventObj = {
				dept: this.dept,
				calDate: this.calDate,
				uploader: this.uploader,
				phone: this.phone,
				content: this.content,
				workStar: this.workStar,
				other: this.other,
				workGroup: this.workGroup
			}
			console.log(eventObj)
			let fileList = this.fileList.map((item) => {
				return item.file
			})

			let formData = new FormData()
			formData.append('workLog', new Blob([JSON.stringify(eventObj)], { type: 'application/json;charset=UTF-8' }))

			fileList.forEach((item, index) => {
				formData.append('muFiles', item)
			})
			axios
				.post(`${window.apiUrl}/api/workLog-report/add`, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
				.then((res) => {
					this.$store.commit('hideLoading')
					if (res.data.code == 200) {
						Toast.success({
							duration: 3000,
							message: '上传成功'
						})
					} else {
						Toast.fail({
							duration: 3000,
							message: '上传失败'
						})
					}
				})
				.catch((e) => {
					this.$store.commit('hideLoading')
					Toast.fail({
						duration: 3000,
						message: e.response.data.msg
					})
				})
		}
	}
}
</script>
<style >
.Box .van-dropdown-menu__bar {
	box-shadow: none;
}
.Box .van-dropdown-menu__bar {
	box-shadow: none;
}
.Box .van-cell__left-icon {
	line-height: 0.96rem;
	font-size: 0.32rem;
}
.Box .van-field__label {
	font-size: 0.32rem;
	font-weight: 500;
	color: #000;
	font-family: PingFangSC, PingFangSC-Medium;
}
.Box .van-cell {
	line-height: 0.96rem;
}
.Box .jobContent .van-cell {
	line-height: 0.5rem;
}
.Box .van-cell__value {
	font-size: 0.28rem;
	font-family: PingFangSC, PingFangSC-Regular;
	font-weight: 400;
	text-align: right;
	color: #e3e3e3;
}
.Box .van-field__control {
	text-align: end;
}
.Box .jobContent .van-field__control {
	text-align: left;
}
.Box .van-dropdown-menu__item {
	justify-content: flex-end;
}
</style>
<style lang="scss" scoped>
.Box {
	.picTitle {
		text-align: left;
		padding: 0.1rem;
		padding-left: 0.3rem;
		line-height: 0.96rem;
		height: 0.96rem;
		font-size: 0.32rem;
		font-weight: 500;
		color: #000;
		font-family: PingFangSC, PingFangSC-Medium;
	}
	.picTitle1 {
		text-align: left;
		padding-left: 0.1rem;
		padding-left: 0.3rem;
		line-height: 0.96rem;
		height: 0.96rem;
		font-size: 0.32rem;
		font-weight: 500;
		color: #000;
		font-family: PingFangSC, PingFangSC-Medium;
	}
	.bottomBtn {
		width: 80%;
		height: 1rem;
		line-height: 1rem;
		margin: 1rem auto;
		margin-bottom: 0.3rem;
		background: #409eff;
		color: #fff;
		font-size: 0.4rem;
		text-align: center;
		border-radius: 0.2rem;
	}
	.empty {
		height: 2rem;
	}
	.daigo {
		width: 100%;
		height: 100vh;
		background: rgba(0, 0, 0, 0.3);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		margin: auto;
		.content {
			width: 6rem;
			height: 3.32rem;
			background: #fff;
			margin: 0 auto;
			margin-top: 4.7rem;
			.tCon {
				width: 3.69rem;
				height: 0.9rem;
				margin: 0 auto;
				padding-top: 0.6rem;
				padding-bottom: 0.9rem;
				font-size: 0.32rem;
				text-align: center;
				line-height: 0.45rem;
				font-weight: 600;
			}
			.tBtn {
				width: 3.69rem;
				display: flex;
				margin: 0 auto;
				justify-content: space-between;
				color: #fff;
				.tbtn1 {
					width: 1.6rem;
					line-height: 0.6rem;
					text-align: center;
					color: #409eff;
					border: 1px solid #409eff;
					border-radius: 0.4rem;
				}
				.tbtn2 {
					width: 1.6rem;
					line-height: 0.6rem;
					text-align: center;
					border-radius: 0.4rem;
					background: #409eff;
				}
			}
		}
	}
}
</style>


